unit VendasFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ComCtrls, ExtCtrls, StdCtrls, Buttons, DBCtrls, DBGrids, EditBtn, MainFr,
  DataRecord, types;

type

  { TVendasMainFrame }

  TVendasMainFrame = class(TMainFrame)
    BotaoLocalizar: TBitBtn;
    InicialDataEdit: TDateEdit;
    FinalDataEdit: TDateEdit;
    DBGrid1: TDBGrid;
    FPagDBLookupComboBox: TDBLookupComboBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    MostrarClienteBtn: TBitBtn;
    Panel1: TPanel;
    ClienteEdit: TEdit;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    procedure BotaoLocalizarClick(Sender: TObject);
    procedure FPagDBLookupComboBoxSelect(Sender: TObject);
    procedure MostrarClienteBtnClick(Sender: TObject);
    procedure SetDataRecord(Data: TDataRecord); override;

  private
    { private declarations }
  public
    { public declarations }
  end;

implementation

uses
  VendaFrDM;

{ TVendasMainFrame }


procedure TVendasMainFrame.FPagDBLookupComboBoxSelect(Sender: TObject);
begin
   VendaFrData.BuscaVendaFormaPagamento(FPagDBLookupComboBox.KeyValue);
end;

procedure TVendasMainFrame.BotaoLocalizarClick(Sender: TObject);
var
  DataInicial, DataFinal:string;
begin
   if InicialDataEdit.Text = '' then begin
     DataInicial:= '2013-01-01';
   end else begin
        DataInicial:=InicialDataEdit.Text;
   end;
   if FinalDataEdit.Text = '' then begin
     DataFinal:= VendaFrData.BuscaData();
     end else begin
     DataFinal:=FinalDataEdit.Text;
   end;
     VendaFrData.BuscaVendaData(DataInicial,DataFinal);
end;

procedure TVendasMainFrame.MostrarClienteBtnClick(Sender: TObject);
begin
    VendaFrData.BuscaVendaCliente(ClienteEdit.Text);
end;

procedure TVendasMainFrame.SetDataRecord(Data: TDataRecord);
begin
  // Verifica se o frame possui módulo de dados
  if (MainDataModule <> nil) then
    // Atribui um DataRecord ao DataSet
    MainDataModule.SetDataRecord(Data);
end;

initialization
  {$I vendasfr.lrs}

end.

